import 'package:flutter/material.dart';

class SegmentedControl extends StatefulWidget {
  final List<String> tabs;
  final ScrollController? controller;
  final EdgeInsetsGeometry? padding;
  final Color? unselectedLabelColor;
  final Color? labelColor;
  final TextStyle? labelStyle;
  final EdgeInsetsGeometry? indicatorPadding;
  final Decoration? indicator;

  SegmentedControl({
    Key? key,
    required this.tabs,
    this.controller,
    this.padding,
    this.unselectedLabelColor,
    this.labelColor,
    this.labelStyle,
    this.indicator,
    this.indicatorPadding,
  }) : super(key: key);

  _SegmentedControlState createState() => _SegmentedControlState();
}

class _SegmentedControlState extends State<SegmentedControl> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 64,
      child: ListView.builder(
          scrollDirection: Axis.horizontal,
          itemCount: widget.tabs.length,
          controller: widget.controller,
          itemBuilder: (context, index) {
            String tab = widget.tabs[index];
            return Container(
              padding: widget.indicatorPadding ?? EdgeInsets.fromLTRB(20, 10, 20, 10),
              margin: EdgeInsets.only(right: 10),
              height: 44,
              child: Text(
                tab,
                style: widget.labelStyle ?? TextStyle(color: widget.unselectedLabelColor, fontSize: 16),
              ),
              decoration: widget.indicator ?? BoxDecoration(
                  color: Colors.white54,
                  borderRadius: BorderRadius.circular(22)),
            );
          }),
    );
  }
}
